package com.yanmushi.ms.webconsole.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * @auther yinlei
 * @date 2018/1/24
 * @since 1.0.0
 */
@Controller
@RequestMapping("direct")
public class DirectTokenController {

    @RequestMapping("index")
    public String index() {
        return "redirect:http://localhost:8080/oauth/authorize?client_id=web-console-trust&response_type=token&redirect_uri=http://localhost:8081/direct/token&scope=read";
    }

    @ResponseBody
    @RequestMapping("token")
    public String token(String access_token, String accessToken) {
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();

        System.out.println(request.getRequestURI());
        return "ok" + access_token + "  " + accessToken;
    }
}
